package com.nd.controller.wx;


import com.nd.pojo.bean.Cart;
import com.nd.pojo.bo.wx.CartCheckOutBo;
import com.nd.pojo.vo.wx.*;
import com.nd.service.wx.CartDeleteVo;
import com.nd.service.wx.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx")
public class CartController {

    @Autowired
    CartService cartService;

    @RequestMapping("cart/index")
    public BaseRespWXVo cartIndex(){
        CartIndexVo CartIndexVo = cartService.queryCarIndexVo();
        return BaseRespWXVo.ok(CartIndexVo);
    }

    @RequestMapping("cart/add")
    public BaseRespWXVo cartAdd(@RequestBody Cart cart){
        Integer add = cartService.addToCart(cart);
        if(add == null) return BaseRespWXVo.fail("添加购物车异常");
        return BaseRespWXVo.ok(add);
    }

    @RequestMapping("cart/fastadd")
    public BaseRespWXVo fastAdd(@RequestBody Cart cart){
        Integer fastAdd = cartService.fastAddToOrder(cart);
        if(fastAdd == null) return BaseRespWXVo.fail("立即购买异常");
        return BaseRespWXVo.ok(fastAdd);
    }

    @RequestMapping("cart/checked")
    public BaseRespWXVo checked(@RequestBody CartCheckedVo cartCheckedVo){
        CartIndexVo checked = cartService.checked(cartCheckedVo);
        if(checked == null) return BaseRespWXVo.fail("更改异常");
        return BaseRespWXVo.ok(checked);
    }

    @RequestMapping("cart/update")
    public BaseRespWXVo update(@RequestBody Cart cart){

        Integer update = cartService.updateCart(cart);
        if(update == 10000) return BaseRespWXVo.fail("修改异常");
        return BaseRespWXVo.ok();
    }
    @RequestMapping("cart/delete")
    public BaseRespWXVo delete(@RequestBody CartDeleteVo cartDeleteVo){
        CartIndexVo deleteVo = cartService.deleteCarts(cartDeleteVo);
        if(deleteVo == null) return BaseRespWXVo.fail("删除异常");
        return BaseRespWXVo.ok(deleteVo);
    }

    @RequestMapping("cart/checkout")
    public BaseRespWXVo checkout(CartCheckOutBo cartCheckOutBo){
        CartCheckoutVo cartCheckoutVo =cartService.queryCartCheckoutVo(cartCheckOutBo);
        return BaseRespWXVo.ok(cartCheckoutVo);
    }

    @RequestMapping("cart/goodscount")
    //购物车商品数量总数
    public BaseRespWXVo goodsCount(){
        int goodsCount = cartService.queryGoodsCount();
        return BaseRespWXVo.ok(goodsCount);
    }


}
